//
//  UserDetailViewController.m
//  豆瓣_精简版
//
//  Created by 张健 on 15/11/8.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "UserDetailViewController.h"
#import "DataBase.h"
#import "MovieDetailViewController.h"
#import "MovieDetail.h"
@interface UserDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,retain)UITableView *myTableView;
@property(nonatomic,retain)NSMutableArray *array;
@end

@implementation UserDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.myTableView = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.view addSubview:self.myTableView];
    
    self.array = [NSMutableArray array];
    NSString *name = [[NSUserDefaults standardUserDefaults]objectForKey:@"user"];
    self.array = [[DataBase shareDataBase]selectMovieUserData:name];
    NSLog(@"%@",self.array);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.textLabel.text = [[self.array objectAtIndex:indexPath.row] movieName];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MovieDetailViewController *movieDVC = [[MovieDetailViewController alloc]init];
    Movie *movieD = [self.array objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:movieDVC animated:YES];
    movieDVC.movie = movieD;

}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
